﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;

namespace MyCalendar.Utils
{
    public class DateTimeTool
    {
        private DateTime mThisDay;
        private Calendar mCalendar = CultureInfo.CurrentCulture.Calendar;

        public DateTimeTool (DateTime pDateTime)
        {
            mThisDay = pDateTime;
        }

        public CalendarPosition ToCalendarPosition ()
        {
            CalendarPosition _Position = new CalendarPosition();

            int _FirstWeek = mCalendar.GetWeekOfYear (new DateTime(mThisDay.Year,mThisDay.Month,1), CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule, DayOfWeek.Sunday);

            _Position.Row = mCalendar.GetWeekOfYear (mThisDay, CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule, DayOfWeek.Sunday)- _FirstWeek +1;

            switch (mThisDay.DayOfWeek)
            {
                case DayOfWeek.Friday:
                    _Position.Column = 6;
                    break;
                case DayOfWeek.Monday:
                    _Position.Column = 2;
                    break;
                case DayOfWeek.Saturday:
                    _Position.Column = 7;
                    break;
                case DayOfWeek.Sunday:
                    _Position.Column = 1;
                    break;
                case DayOfWeek.Thursday:
                    _Position.Column = 5;
                    break;
                case DayOfWeek.Tuesday:
                    _Position.Column = 3;
                    break;
                case DayOfWeek.Wednesday:
                    _Position.Column = 4;
                    break;
                default:
                    break;
            }

            return _Position;
        }

        public static int GetTotalDaysInThisMonth (DateTime pDateTime)
        {
            DateTime _Day = new DateTime (pDateTime.Year, pDateTime.Month, 1);
            return _Day.AddMonths (1).AddDays (-1).Day;
        }
    }

    public class CalendarPosition
    {
        public int Row
        {
            get;
            set;
        }

        public int Column
        {
            get;
            set;
        }
    }
}
